package com.gbiac.modules.monitor.controller;

import com.alibaba.fastjson.JSONObject;
import com.gbiac.modules.monitor.entity.PalmVeinRecord;
import com.gbiac.modules.monitor.model.dto.PalmVeinDeviceLoginParamDTO;
import com.gbiac.modules.monitor.model.dto.PalmVeinDevicePassRecordParamDTO;
import com.gbiac.modules.monitor.service.IPalmVeinRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
* @Description: 掌静脉上传接口
* @Author: jeecg-boot
* @Date:   2024-11-30
* @Version: V1.0
*/
@Api(tags="掌静脉上传接口")
@RestController
@RequestMapping("/upload")
@Slf4j
public class UploadController  {

   @Resource
   private IPalmVeinRecordService palmVeinRecordService;
   @Resource
   private ISysBaseAPI iSysBaseAPI;


    /**
     * 添加掌静脉通行记录-回调接口
     *
     * @param palmVeinDevicePassRecordParamDTO
     * @return
     */
    @AutoLog(value = "添加掌静脉通行记录-回调接口")
    @ApiOperation(value="添加掌静脉通行记录-回调接口", notes="添加掌静脉通行记录-回调接口")
    @PostMapping(value = "/passRecord/{sn}")
    public Result<String> passRecord(@RequestBody PalmVeinDevicePassRecordParamDTO palmVeinDevicePassRecordParamDTO, @PathVariable String sn) {

        log.info("===palmVeinDevicePassRecordParamDTO：{}", palmVeinDevicePassRecordParamDTO);
        String personId = palmVeinDevicePassRecordParamDTO.getPersonId();
        LoginUser user = iSysBaseAPI.getUserById(personId);
        if(user==null){
            log.info("===添加通行记录失败，用户不存在，id:{}",personId);
            return Result.ok("添加通行记录失败，用户不存在");
        }
        PalmVeinRecord palmVeinRecord = new PalmVeinRecord();
        palmVeinRecord.setCreateBy("0");
        palmVeinRecord.setCreateTime(new Date());
        palmVeinRecord.setUpdateBy("0");
        palmVeinRecord.setUpdateTime(new Date());
        palmVeinRecord.setDelFlag(0);
        palmVeinRecord.setSysOrgCode(user.getOrgCode());
        palmVeinRecord.setOrgCode(user.getOrgCode());
        palmVeinRecord.setUserId(user.getId());
        palmVeinRecord.setUsername(user.getUsername());
        palmVeinRecord.setRealname(user.getRealname());
        palmVeinRecord.setPhone(user.getPhone());
        palmVeinRecord.setUserType(user.getUserType());
        palmVeinRecord.setRoleCode(user.getRoleList().get(0).getRoleCode());
        palmVeinRecord.setRoleName(user.getRoleList().get(0).getRoleName());
        palmVeinRecord.setCheckInTime(palmVeinDevicePassRecordParamDTO.getPassTime());
        palmVeinRecordService.save(palmVeinRecord);
        log.info("===添加通行记录成功");
        return Result.OK("添加成功！");
    }

}
